package com.dragon.client.controller.contract;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.logical.service.contract.ISchedulingOutService;
import com.dragon.repository.domain.dto.SchedulingOutDTO;
import com.dragon.repository.domain.vo.SchedulingOutVO;
import com.dragon.repository.entity.SchedulingOut;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 外发 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-11-29
 */
@RestController
@RequestMapping("schedulingOut")
@Api(tags = "外发")
public class SchedulingOutController {

    @Autowired
    ISchedulingOutService service;

    @GetMapping("list")
    @ApiOperation(value = "列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, type = "int"),
            @ApiImplicitParam(name = "limit", value = "条数", required = true, type = "int"),
            @ApiImplicitParam(name = "type", value = "状态", required = false, type = "int"),
            @ApiImplicitParam(name = "search", value = "搜索参数", required = false, type = "string")
    })
    public ResponseData<List<SchedulingOutDTO>> list(@RequestParam Integer page,
                                                     @RequestParam Integer limit,
                                                     @RequestParam(required = false) Integer type,
                                                     @RequestParam(required = false) String search){
        Page<SchedulingOut> outPage = service.schedulingOutList(page, limit, type, search);
        return ResponseData.success(SchedulingOutDTO.convertList(outPage.getRecords()), outPage.getTotal());
    }

    @PostMapping("add")
    @ApiOperation(value = "添加")
    public ResponseData schedulingOutAdd(@RequestBody @Validated(Insert.class) SchedulingOutVO vo) {
        service.schedulingOutAdd(SchedulingOutVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("enter")
    @ApiOperation(value = "录入数据")
    public ResponseData enterDate(@RequestBody @Validated(Insert.class) SchedulingOutVO vo){
        service.enterDateOut(SchedulingOutVO.convert(vo));
        return ResponseData.success();
    }

    @GetMapping("detail")
    @ApiOperation(value = "查详情")
    public ResponseData<SchedulingOutDTO> oneDetail(
            @ApiParam(name = "id", value = "id", required = true, type = "int")
            @RequestParam Integer id){
        SchedulingOut schedulingOut = service.selectOneDetail(id);
        return ResponseData.success(SchedulingOutDTO.convert(schedulingOut));
    }

}
